


#include <iostream>
#include <vector>
#include <string>
using namespace std;



struct ListNode 
{
	int val;
	struct ListNode *next;
	ListNode(int x) :val(x), next(NULL) {}
};

class Solution {
public:
	ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2)
	{
		if (!(pHead1 && pHead2))
			return nullptr;

		int cnt1 = 0, cnt2 = 0;
		ListNode* cur1 = pHead1, * cur2 = pHead2;

		while (cur1)
		{
			++cnt1;
			cur1 = cur1->next;
		}
		while (cur2)
		{
			++cnt2;
			cur2 = cur2->next;
		}

		cur1 = pHead1, cur2 = pHead2;
		if (cnt1 < cnt2)
		{
			swap(cur1, cur2);
			swap(cnt1, cnt2);
		}

		while (cnt1 != cnt2)
		{
			cur1 = cur1->next;
			--cnt1;
		}

		while (cur1 && cur2 && cur1 != cur2)
		{
			cur1 = cur1->next;
			cur2 = cur2->next;
		}

		return cur1;
	}

	void Test2()
	{
		string s1, s2, res;
		getline(cin, s1);
		getline(cin, s2);

		int hash[128] = { 0 };
		for (const auto e : s2)
		{
			++hash[e];
		}

		for (const auto e : s1)
		{
			if (!hash[e])
				res += e;
		}

		cout << res << endl;
	}
};

ListNode* CreateList1()
{
	ListNode* l1 = new ListNode(1);

	return l1;
}

ListNode* CreateList2()
{
	ListNode* l2 = new ListNode(2);
	ListNode* l3 = new ListNode(3);
	l2->next = l3;

	return l2;
}

void Test1()
{
	ListNode* l1 = CreateList1();
	ListNode* l2 = CreateList2();

	Solution().FindFirstCommonNode(l1, l2);
}

int main()
{
	Test1();

	return 0;
}